/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.bsa.soft.i18nparser.core;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author vdusa
 */
public class ParameterList extends ArrayList<Parameter> implements I18nPropertiesParser {
    @Override
    public String toString() {
        String result = "";
        for (Parameter param : this) {
            result += (result.equals("") ? "" : ",") + param;
        }
        return result;
    }

    public Set<I18nProperty> getI18nProperties() {
        Set<I18nProperty> result = new HashSet<I18nProperty>();
        for (Parameter param : this) {
            I18nPropertiesParser parser = (I18nPropertiesParser) param;
            result.addAll(parser.getI18nProperties());
        }

        return result;
    }

    public I18nProperty getI18nProperty() {
        String code = null;
        String defaultValue = null;

        for (Parameter param : this) {
            if (param.name.equals("code")) {
                code = param.value.toString();
            }
            if (param.name.equals("default")) {
                defaultValue = param.value.toString();
            }
        }

        if (code == null) {
            return null;
        } else {
            return new I18nProperty(code, defaultValue);
        }
    }
}
